---
title: "2021 US MTurk IHL Survey Code"
output:
  html_document: default
  pdf_document: default
header-includes: \usepackage{dcolumn}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Packages
```{r, include = F} 
require(tidyverse)
require(lubridate)
library(ggplot2)
library(stargazer)
require(estimatr) 
require(multiwayvcov)
require(plm)
require(lmtest)
library(tidyverse)
library(data.table)
library(gtools)
library(lubridate)
library(AER)
library(xtable)
library(pBrackets)
library(Hmisc)
library(car)
library(ri)
library(psych)
library(ggpubr)
library(ivpack)
require(optmatch)
require(mediation)
library(gtsummary)
library(arm)
library(bda)
library(multilevel)
require(nnet) 
require(foreign)
require(reshape2)
require(forcats)
```

# PAP Work

## Input Emotions Data Together
```{r Emotions Data Together}

# Put Emotional Humanity and Valence Information Together
Humanity <- c(5.63, 5.44, 5.44, 5.15, 4.7, 5.48, 5.37, 5.19, 4.93, 4.7, 2.93, 2.37, 1.85, 1.59, 3.07, 2.3, 2.85, 2.37, 2.74, 3.52) 
Valence <- c(6.07, 4.89, 6.3, 5.63, 6.96, 2.52, 2.52, 2.11, 2.04, 2.26, 2, 2.59,  2.78, 2.37, 2.44, 5.3, 5.81, 6.67, 6.59, 5.52) 
Emotion <- c("Optimism", "Nostalgia", "Hope", "Admiration", "Love", "Humiliation", "Guilt", "Resentment", "Disgust", "Disenchantment", "Irritation", "Anger", "Fear", "Pain", "Sadness", "Surprise", "Calmness", "Affection", "Caring", "Desire")
prim_sec_emotions_df <- data.frame(Emotion, Humanity, Valence)


```

## Emotions Dimensionality T-Test and Random Shuffle of Emotions
```{r Emotions T Test}
t.test(prim_sec_emotions_df$Humanity[1:5], prim_sec_emotions_df$Humanity[6:10]) # T-test of humanity between negative and positive secondary emotions = NOT significant difference

t.test(prim_sec_emotions_df$Valence[1:5], prim_sec_emotions_df$Valence[16:20]) # T-test of positive primary and secondary valence scores = NOT significant difference

t.test(prim_sec_emotions_df$Valence[6:10], prim_sec_emotions_df$Valence[11:15]) # T-test of negative primary and secondary valence scores = NOT significant difference

t.test(prim_sec_emotions_df$Valence[1:10], prim_sec_emotions_df$Valence[11:20]) # T-test of overall primary and secondary valence scores = NOT significant difference

t.test(prim_sec_emotions_df$Humanity[1:10], prim_sec_emotions_df$Humanity[11:20]) # T-test of humanity of primary and secondary emotions = YES significant difference

t.test(prim_sec_emotions_df$Valence[1:5 & 16:20], prim_sec_emotions_df$Valence[6:15]) #T-test of valence of positive v. negative = YES significant difference

# Shuffle the rows randomly
set.seed(1234)
random_emotions <- sample(nrow(prim_sec_emotions_df))
prim_sec_emotions_random <- prim_sec_emotions_df[random_emotions, ]
prim_sec_emotions_random # random assignment
prim_sec_emotions_df # original dataframe
```

# Thesis Work 

## Condition Variable 
```{r Condition Variable, warning = F}

# Import the dataset and delete the first two rows

emotions_survey_text <- read_csv("2021.US.MTurk.IHL.Survey.Data.csv")
emotions_survey_text <- emotions_survey_text[-c(1:2),] # delete the first two descriptive rows

# Make the Condition Variable

emotions_survey_text <- emotions_survey_text %>%
  mutate(Condition = ifelse(is.na(age_question_1) == F, 1, ifelse(is.na(vegi_question) == F, 2, 0)))


```

## Emotions Score Outcome Variable
```{r Emotions Score}

emotions_survey_text <- emotions_survey_text %>%
  
  separate(emotions, into = c("e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "e10"), sep = ",", remove = F) %>% # remove = F ensures that not removing the original input from the output dataframe
  
  mutate(e2_1 = ifelse(e2 == "Anger", 0, ifelse(e2 == "Sadness", 0, ifelse(e2 == "Optimism", 1, ifelse(e2 == "Nostalgia", 1, ifelse(e2 == "Hope", 1, ifelse(e2 == "Admiration", 1, ifelse(e2 == "Love", 1, ifelse(e2 == "Humiliation", 1, ifelse(e2 == "Guilt", 1, ifelse(e2 == "Resentment", 1, ifelse(e2 == "Disgust", 1, ifelse(e2 == "Disenchantment", 1, ifelse(e2 == "Irritation", 0, ifelse(e2 == "Fear", 0, ifelse(e2 == "Pain", 0, ifelse(e2 == "Surprise", 0, ifelse(e2 == "Calmness", 0, ifelse(e2 == "Affection", 0, ifelse(e2 == "Caring", 0, ifelse(e2 == "Desire", 0, NA))))))))))))))))))))) %>% 
  
  mutate(e1_1 = ifelse(e1 == "Anger", 0, ifelse(e1 == "Sadness", 0, ifelse(e1 == "Optimism", 1, ifelse(e1 == "Nostalgia", 1, ifelse(e1 == "Hope", 1, ifelse(e1 == "Admiration", 1, ifelse(e1 == "Love", 1, ifelse(e1 == "Humiliation", 1, ifelse(e1 == "Guilt", 1, ifelse(e1 == "Resentment", 1, ifelse(e1 == "Disgust", 1, ifelse(e1 == "Disenchantment", 1, ifelse(e1 == "Irritation", 0, ifelse(e1 == "Fear", 0, ifelse(e1 == "Pain", 0, ifelse(e1 == "Surprise", 0, ifelse(e1 == "Calmness", 0, ifelse(e1 == "Affection", 0, ifelse(e1 == "Caring", 0, ifelse(e1 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e4_1 = ifelse(e4 == "Anger", 0, ifelse(e4 == "Sadness", 0, ifelse(e4 == "Optimism", 1, ifelse(e4 == "Nostalgia", 1, ifelse(e4 == "Hope", 1, ifelse(e4 == "Admiration", 1, ifelse(e4 == "Love", 1, ifelse(e4 == "Humiliation", 1, ifelse(e4 == "Guilt", 1, ifelse(e4 == "Resentment", 1, ifelse(e4 == "Disgust", 1, ifelse(e4 == "Disenchantment", 1, ifelse(e4 == "Irritation", 0, ifelse(e4 == "Fear", 0, ifelse(e4 == "Pain", 0, ifelse(e4 == "Surprise", 0, ifelse(e4 == "Calmness", 0, ifelse(e4 == "Affection", 0, ifelse(e4 == "Caring", 0, ifelse(e4 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e3_1 = ifelse(e3 == "Anger", 0, ifelse(e3 == "Sadness", 0, ifelse(e3 == "Optimism", 1, ifelse(e3 == "Nostalgia", 1, ifelse(e3 == "Hope", 1, ifelse(e3 == "Admiration", 1, ifelse(e3 == "Love", 1, ifelse(e3 == "Humiliation", 1, ifelse(e3 == "Guilt", 1, ifelse(e3 == "Resentment", 1, ifelse(e3 == "Disgust", 1, ifelse(e3 == "Disenchantment", 1, ifelse(e3 == "Irritation", 0, ifelse(e3 == "Fear", 0, ifelse(e3 == "Pain", 0, ifelse(e3 == "Surprise", 0, ifelse(e3 == "Calmness", 0, ifelse(e3 == "Affection", 0, ifelse(e3 == "Caring", 0, ifelse(e3 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e5_1 = ifelse(e5 == "Anger", 0, ifelse(e5 == "Sadness", 0, ifelse(e5 == "Optimism", 1, ifelse(e5 == "Nostalgia", 1, ifelse(e5 == "Hope", 1, ifelse(e5 == "Admiration", 1, ifelse(e5 == "Love", 1, ifelse(e5 == "Humiliation", 1, ifelse(e5 == "Guilt", 1, ifelse(e5 == "Resentment", 1, ifelse(e5 == "Disgust", 1, ifelse(e5 == "Disenchantment", 1, ifelse(e5 == "Irritation", 0, ifelse(e5 == "Fear", 0, ifelse(e5 == "Pain", 0, ifelse(e5 == "Surprise", 0, ifelse(e5 == "Calmness", 0, ifelse(e5 == "Affection", 0, ifelse(e5 == "Caring", 0, ifelse(e5 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e6_1 = ifelse(e6 == "Anger", 0, ifelse(e6 == "Sadness", 0, ifelse(e6 == "Optimism", 1, ifelse(e6 == "Nostalgia", 1, ifelse(e6 == "Hope", 1, ifelse(e6 == "Admiration", 1, ifelse(e6 == "Love", 1, ifelse(e6 == "Humiliation", 1, ifelse(e6 == "Guilt", 1, ifelse(e6 == "Resentment", 1, ifelse(e6 == "Disgust", 1, ifelse(e6 == "Disenchantment", 1, ifelse(e6 == "Irritation", 0, ifelse(e6 == "Fear", 0, ifelse(e6 == "Pain", 0, ifelse(e6 == "Surprise", 0, ifelse(e6 == "Calmness", 0, ifelse(e6 == "Affection", 0, ifelse(e6 == "Caring", 0, ifelse(e6 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e7_1 = ifelse(e7 == "Anger", 0, ifelse(e7 == "Sadness", 0, ifelse(e7 == "Optimism", 1, ifelse(e7 == "Nostalgia", 1, ifelse(e7 == "Hope", 1, ifelse(e7 == "Admiration", 1, ifelse(e7 == "Love", 1, ifelse(e7 == "Humiliation", 1, ifelse(e7 == "Guilt", 1, ifelse(e7 == "Resentment", 1, ifelse(e7 == "Disgust", 1, ifelse(e7 == "Disenchantment", 1, ifelse(e7 == "Irritation", 0, ifelse(e7 == "Fear", 0, ifelse(e7 == "Pain", 0, ifelse(e7 == "Surprise", 0, ifelse(e7 == "Calmness", 0, ifelse(e7 == "Affection", 0, ifelse(e7 == "Caring", 0, ifelse(e7 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e8_1 = ifelse(e8 == "Anger", 0, ifelse(e8 == "Sadness", 0, ifelse(e8 == "Optimism", 1, ifelse(e8 == "Nostalgia", 1, ifelse(e8 == "Hope", 1, ifelse(e8 == "Admiration", 1, ifelse(e8 == "Love", 1, ifelse(e8 == "Humiliation", 1, ifelse(e8 == "Guilt", 1, ifelse(e8 == "Resentment", 1, ifelse(e8 == "Disgust", 1, ifelse(e8 == "Disenchantment", 1, ifelse(e8 == "Irritation", 0, ifelse(e8 == "Fear", 0, ifelse(e8 == "Pain", 0, ifelse(e8 == "Surprise", 0, ifelse(e8 == "Calmness", 0, ifelse(e8 == "Affection", 0, ifelse(e8 == "Caring", 0, ifelse(e8 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e9_1 = ifelse(e9 == "Anger", 0, ifelse(e9 == "Sadness", 0, ifelse(e9 == "Optimism", 1, ifelse(e9 == "Nostalgia", 1, ifelse(e9 == "Hope", 1, ifelse(e9 == "Admiration", 1, ifelse(e9 == "Love", 1, ifelse(e9 == "Humiliation", 1, ifelse(e9 == "Guilt", 1, ifelse(e9 == "Resentment", 1, ifelse(e9 == "Disgust", 1, ifelse(e9 == "Disenchantment", 1, ifelse(e9 == "Irritation", 0, ifelse(e9 == "Fear", 0, ifelse(e9 == "Pain", 0, ifelse(e9 == "Surprise", 0, ifelse(e9 == "Calmness", 0, ifelse(e9 == "Affection", 0, ifelse(e9 == "Caring", 0, ifelse(e9 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e10_1 = ifelse(e10 == "Anger", 0, ifelse(e10 == "Sadness", 0, ifelse(e10 == "Optimism", 1, ifelse(e10 == "Nostalgia", 1, ifelse(e10 == "Hope", 1, ifelse(e10 == "Admiration", 1, ifelse(e10 == "Love", 1, ifelse(e10 == "Humiliation", 1, ifelse(e10 == "Guilt", 1, ifelse(e10 == "Resentment", 1, ifelse(e10 == "Disgust", 1, ifelse(e10 == "Disenchantment", 1, ifelse(e10 == "Irritation", 0, ifelse(e10 == "Fear", 0, ifelse(e10 == "Pain", 0, ifelse(e10 == "Surprise", 0, ifelse(e10 == "Calmness", 0, ifelse(e10 == "Affection", 0, ifelse(e10 == "Caring", 0, ifelse(e10 == "Desire", 0, NA))))))))))))))))))))) 

emotions_survey_text <- emotions_survey_text %>%
  mutate(EmotionScore = rowSums(emotions_survey_text[,93:102]))

```


## Moral Exclusion score
```{r Moral Exclusion Score}

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(morals1_1 = ifelse(morals1 == "Totally unacceptable", 7, ifelse(morals1 == "Unacceptable", 6, ifelse(morals1 == "Slightly unacceptable", 5, ifelse(morals1 == "Neutral", 4, ifelse(morals1 == "Slightly acceptable", 3, ifelse(morals1 == "Acceptable", 2, ifelse(morals1 == "Perfectly acceptable", 1, NA)))))))) %>%

  mutate(morals2_1 = ifelse(morals2 == "Totally unacceptable", 7, ifelse(morals2 == "Unacceptable", 6, ifelse(morals2 == "Slightly unacceptable", 5, ifelse(morals2 == "Neutral", 4, ifelse(morals2 == "Slightly acceptable", 3, ifelse(morals2 == "Acceptable", 2, ifelse(morals2 == "Perfectly Acceptable", 1, NA)))))))) %>%
  
  mutate(morals3_1 = ifelse(morals3 == "Totally unacceptable", 7, ifelse(morals3 == "Unacceptable", 6, ifelse(morals3 == "Slightly unacceptable", 5, ifelse(morals3 == "Neutral", 4, ifelse(morals3 == "Slightly acceptable", 3, ifelse(morals3 == "Acceptable", 2, ifelse(morals3 == "Perfectly acceptable", 1, NA)))))))) %>%
  
  mutate(morals4_1 = ifelse(morals4 == "Totally unacceptable", 7, ifelse(morals4 == "Unacceptable", 6, ifelse(morals4 == "Slightly unacceptable", 5, ifelse(morals4 == "Neutral", 4, ifelse(morals4 == "Slightly acceptable", 3, ifelse(morals4 == "Acceptable", 2, ifelse(morals4 == "Perfectly acceptable", 1, NA)))))))) %>%
  
  mutate(morals5_1 = ifelse(morals5 == "Totally unacceptable", 7, ifelse(morals5 == "Unacceptable", 6, ifelse(morals5 == "Slightly unacceptable", 5, ifelse(morals5 == "Neutral", 4, ifelse(morals5 == "Slightly acceptable", 3, ifelse(morals5 == "Acceptable", 2, ifelse(morals5 == "Perfectly acceptable", 1, NA)))))))) %>%
  
  mutate(morals6_1 = ifelse(morals6 == "Totally unacceptable", 7, ifelse(morals6 == "Unacceptable", 6, ifelse(morals6 == "Slightly unacceptable", 5, ifelse(morals6 == "Neutral", 4, ifelse(morals6 == "Slightly acceptable", 3, ifelse(morals6 == "Acceptable", 2, ifelse(morals6 == "Perfectly acceptable", 1, NA)))))))) 

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(MoralScore = rowMeans(emotions_survey_text[,104:109]))

```

## Pre-treatment covariates, timing and post-treatment followup questions 

```{r Pre-treatment Covariates} 

# Age (in years) 

emotions_survey_text <- emotions_survey_text %>%
  mutate(age = as.numeric(age_years_1))

# Nationality

emotions_survey_text <- emotions_survey_text %>%
  mutate(Nationality = ifelse(nationality == "United States of America", 1, ifelse(nationality != "United States of America", 0, NA))) # The effect of being a national of the USA as opposed to other countries

# NatID

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(NatID = ifelse(nat_id == "Not at all", 1, ifelse(nat_id == "A little", 2, ifelse(nat_id == "A moderate amount", 3, ifelse(nat_id == "A lot", 4, ifelse(nat_id == "A great deal", 5, NA)))))) # increasing NatID, increased identification with nationality

# Gender 

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(Gender = ifelse(gender == "Male", 1, ifelse(gender == "Female", 2, ifelse(gender == "Non-binary", 3, ifelse(gender == "Other", 4, NA)))))


# Religion

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(Religion = ifelse(religion == "Yes", 1, ifelse(religion == "No", 0, NA))) %>%
  
  mutate(ReligType = ifelse(relig_type == "Christianity", 1, ifelse(relig_type == "Judaism", 2, ifelse(relig_type == "Islam", 3, ifelse(relig_type == "Hinduism", 4, ifelse(relig_type == "Buddhism", 5, ifelse(relig_type == "Sikhism", 6, ifelse(relig_type == "Other", 7, NA)))))))) 

# Race

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(Race = ifelse(race == "White", 1, ifelse(race == "Hispanic or Latino", 2, ifelse(race == "Black or African American", 3, ifelse(race == "Asian", 4, ifelse(race == "American Indian or Alaska Native", 5, ifelse(race == "Native Hawaiian or Other Pacific Islander", 6, ifelse(race == "Mix/Other", 7, NA))))))))

# PolID

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(PolID = ifelse(politics == "Extremely Liberal", 1, ifelse(politics == "Liberal", 2, ifelse(politics == "Moderate", 3, ifelse(politics == "Conservative", 4, ifelse(politics == "Extremely Conservative", 5, NA)))))) # Higher score as more conservative

# Combatant

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(Combatant = ifelse(combat1 == "No", 0, ifelse(combat1 == "Yes, government soldier", 1, ifelse(combat1 == "Yes, other combatant", 1, NA)))) 

# CombExp

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(CombExp = ifelse(combat2 == "No", 0, ifelse(combat2 == "Yes, in combat", 1, ifelse(combat2 == "Yes, near combat", 1, NA))))


# ConflZone 

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(ConflZone = ifelse(confl_zone == "No", 0, ifelse(confl_zone == "Yes", 1, NA)))

# IHLScore

emotions_survey_text <- emotions_survey_text %>%
  
  mutate(ihl1_1 = ifelse(ihl1 == "Yes", 1, ifelse(ihl1 == "No", 0, NA))) %>%
  
  mutate(ihl2_1 = ifelse(ihl2 == "Yes", 0, ifelse(ihl2 == "No", 1, NA))) %>%
  
  mutate(ihl3_1 = ifelse(ihl3 == "Yes", 0, ifelse(ihl3 == "No", 1, NA))) %>%
  
  mutate(ihl4_1 = ifelse(ihl4 == "Yes", 1, ifelse(ihl4 == "No", 0, NA))) %>%
  
  mutate(ihl5_1 = ifelse(ihl5 == "Yes", 0, ifelse(ihl5 == "No", 1, NA))) %>%
  
  mutate(ihl6_1 = ifelse(ihl6 == "Yes", 1, ifelse(ihl6 == "No", 0, NA)))

emotions_survey_text <- emotions_survey_text %>%
  mutate(IHLScore = rowSums(emotions_survey_text[,122:127])/6)


# followup1 Compliance - In the passage you read earlier, which of the following was involved or questioned about?

emotions_survey_text <- emotions_survey_text %>%
  mutate(followup1_1 = ifelse(followup1 == "A soccer match", 0, ifelse(followup1 == "Soldiers' average age", 1, ifelse(followup1 == "Soldiers' food preference", 2, NA))))

# followup2 - Non-naivete: Have you completed a survey substantially similar to this one before?

emotions_survey_text <- emotions_survey_text %>%
  mutate(followup2_1 = ifelse(followup2 == "No", 0, ifelse(followup2 == "Yes", 1, NA)))

# followup3 - Compliers: Is followup1 = Condition? 

emotions_survey_text <- emotions_survey_text %>%
  mutate(followup3_1 = ifelse(followup1_1 == Condition, 1, ifelse(followup1_1 != Condition, 0, NA)))

# Duration Variable - Time to take the whole survey

emotions_survey_text <- emotions_survey_text %>%
  mutate(duration = as.numeric(`Duration (in seconds)`))

# Placebo Condition Prime Timing

emotions_survey_text <- emotions_survey_text %>%
  mutate(plac_timing = as.numeric(emotions_survey_text$`timing_placebo_Page Submit`))

# Age Condition Prime Timing

emotions_survey_text <- emotions_survey_text %>%
  mutate(age_timing = as.numeric(emotions_survey_text$`timing_age_Page Submit`))

# Vegi Condition Prime Timing

emotions_survey_text <- emotions_survey_text %>%
  mutate(vegi_timing = as.numeric(emotions_survey_text$`vegi_timing_Page Submit`))

# Percents As Numeric

emotions_survey_text <- emotions_survey_text %>%
  mutate(percent1 = as.numeric(emotions_survey_text$percent1_1)) %>%
  mutate(percent2 = as.numeric(emotions_survey_text$percent2_1)) %>%
  mutate(percent3 = as.numeric(emotions_survey_text$percent3_1)) %>%
  mutate(percent4 = as.numeric(emotions_survey_text$percent4_1)) %>%
  mutate(percent5 = as.numeric(emotions_survey_text$percent5_1)) %>%
  mutate(percent6 = as.numeric(emotions_survey_text$percent6_1))


# Positive Secondary Emotions Score
emotions_survey_text <- emotions_survey_text %>%
  
  mutate(e2_2 = ifelse(e2 == "Anger", 0, ifelse(e2 == "Sadness", 0, ifelse(e2 == "Optimism", 1, ifelse(e2 == "Nostalgia", 1, ifelse(e2 == "Hope", 1, ifelse(e2 == "Admiration", 1, ifelse(e2 == "Love", 1, ifelse(e2 == "Humiliation", 0, ifelse(e2 == "Guilt", 0, ifelse(e2 == "Resentment", 0, ifelse(e2 == "Disgust", 0, ifelse(e2 == "Disenchantment", 0, ifelse(e2 == "Irritation", 0, ifelse(e2 == "Fear", 0, ifelse(e2 == "Pain", 0, ifelse(e2 == "Surprise", 0, ifelse(e2 == "Calmness", 0, ifelse(e2 == "Affection", 0, ifelse(e2 == "Caring", 0, ifelse(e2 == "Desire", 0, NA))))))))))))))))))))) %>% 
  
  mutate(e1_2 = ifelse(e1 == "Anger", 0, ifelse(e1 == "Sadness", 0, ifelse(e1 == "Optimism", 1, ifelse(e1 == "Nostalgia", 1, ifelse(e1 == "Hope", 1, ifelse(e1 == "Admiration", 1, ifelse(e1 == "Love", 1, ifelse(e1 == "Humiliation", 0, ifelse(e1 == "Guilt", 0, ifelse(e1 == "Resentment", 0, ifelse(e1 == "Disgust", 0, ifelse(e1 == "Disenchantment", 0, ifelse(e1 == "Irritation", 0, ifelse(e1 == "Fear", 0, ifelse(e1 == "Pain", 0, ifelse(e1 == "Surprise", 0, ifelse(e1 == "Calmness", 0, ifelse(e1 == "Affection", 0, ifelse(e1 == "Caring", 0, ifelse(e1 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e4_2 = ifelse(e4 == "Anger", 0, ifelse(e4 == "Sadness", 0, ifelse(e4 == "Optimism", 1, ifelse(e4 == "Nostalgia", 1, ifelse(e4 == "Hope", 1, ifelse(e4 == "Admiration", 1, ifelse(e4 == "Love", 1, ifelse(e4 == "Humiliation", 0, ifelse(e4 == "Guilt", 0, ifelse(e4 == "Resentment", 0, ifelse(e4 == "Disgust", 0, ifelse(e4 == "Disenchantment", 0, ifelse(e4 == "Irritation", 0, ifelse(e4 == "Fear", 0, ifelse(e4 == "Pain", 0, ifelse(e4 == "Surprise", 0, ifelse(e4 == "Calmness", 0, ifelse(e4 == "Affection", 0, ifelse(e4 == "Caring", 0, ifelse(e4 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e3_2 = ifelse(e3 == "Anger", 0, ifelse(e3 == "Sadness", 0, ifelse(e3 == "Optimism", 1, ifelse(e3 == "Nostalgia", 1, ifelse(e3 == "Hope", 1, ifelse(e3 == "Admiration", 1, ifelse(e3 == "Love", 1, ifelse(e3 == "Humiliation", 0, ifelse(e3 == "Guilt", 0, ifelse(e3 == "Resentment", 0, ifelse(e3 == "Disgust", 0, ifelse(e3 == "Disenchantment", 0, ifelse(e3 == "Irritation", 0, ifelse(e3 == "Fear", 0, ifelse(e3 == "Pain", 0, ifelse(e3 == "Surprise", 0, ifelse(e3 == "Calmness", 0, ifelse(e3 == "Affection", 0, ifelse(e3 == "Caring", 0, ifelse(e3 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e5_2 = ifelse(e5 == "Anger", 0, ifelse(e5 == "Sadness", 0, ifelse(e5 == "Optimism", 1, ifelse(e5 == "Nostalgia", 1, ifelse(e5 == "Hope", 1, ifelse(e5 == "Admiration", 1, ifelse(e5 == "Love", 1, ifelse(e5 == "Humiliation", 0, ifelse(e5 == "Guilt", 0, ifelse(e5 == "Resentment", 0, ifelse(e5 == "Disgust", 0, ifelse(e5 == "Disenchantment", 0, ifelse(e5 == "Irritation", 0, ifelse(e5 == "Fear", 0, ifelse(e5 == "Pain", 0, ifelse(e5 == "Surprise", 0, ifelse(e5 == "Calmness", 0, ifelse(e5 == "Affection", 0, ifelse(e5 == "Caring", 0, ifelse(e5 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e6_2 = ifelse(e6 == "Anger", 0, ifelse(e6 == "Sadness", 0, ifelse(e6 == "Optimism", 1, ifelse(e6 == "Nostalgia", 1, ifelse(e6 == "Hope", 1, ifelse(e6 == "Admiration", 1, ifelse(e6 == "Love", 1, ifelse(e6 == "Humiliation", 0, ifelse(e6 == "Guilt", 0, ifelse(e6 == "Resentment", 0, ifelse(e6 == "Disgust", 0, ifelse(e6 == "Disenchantment", 0, ifelse(e6 == "Irritation", 0, ifelse(e6 == "Fear", 0, ifelse(e6 == "Pain", 0, ifelse(e6 == "Surprise", 0, ifelse(e6 == "Calmness", 0, ifelse(e6 == "Affection", 0, ifelse(e6 == "Caring", 0, ifelse(e6 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e7_2 = ifelse(e7 == "Anger", 0, ifelse(e7 == "Sadness", 0, ifelse(e7 == "Optimism", 1, ifelse(e7 == "Nostalgia", 1, ifelse(e7 == "Hope", 1, ifelse(e7 == "Admiration", 1, ifelse(e7 == "Love", 1, ifelse(e7 == "Humiliation", 0, ifelse(e7 == "Guilt", 0, ifelse(e7 == "Resentment", 0, ifelse(e7 == "Disgust", 0, ifelse(e7 == "Disenchantment", 0, ifelse(e7 == "Irritation", 0, ifelse(e7 == "Fear", 0, ifelse(e7 == "Pain", 0, ifelse(e7 == "Surprise", 0, ifelse(e7 == "Calmness", 0, ifelse(e7 == "Affection", 0, ifelse(e7 == "Caring", 0, ifelse(e7 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e8_2 = ifelse(e8 == "Anger", 0, ifelse(e8 == "Sadness", 0, ifelse(e8 == "Optimism", 1, ifelse(e8 == "Nostalgia", 1, ifelse(e8 == "Hope", 1, ifelse(e8 == "Admiration", 1, ifelse(e8 == "Love", 1, ifelse(e8 == "Humiliation", 0, ifelse(e8 == "Guilt", 0, ifelse(e8 == "Resentment", 0, ifelse(e8 == "Disgust", 0, ifelse(e8 == "Disenchantment", 0, ifelse(e8 == "Irritation", 0, ifelse(e8 == "Fear", 0, ifelse(e8 == "Pain", 0, ifelse(e8 == "Surprise", 0, ifelse(e8 == "Calmness", 0, ifelse(e8 == "Affection", 0, ifelse(e8 == "Caring", 0, ifelse(e8 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e9_2 = ifelse(e9 == "Anger", 0, ifelse(e9 == "Sadness", 0, ifelse(e9 == "Optimism", 1, ifelse(e9 == "Nostalgia", 1, ifelse(e9 == "Hope", 1, ifelse(e9 == "Admiration", 1, ifelse(e9 == "Love", 1, ifelse(e9 == "Humiliation", 0, ifelse(e9 == "Guilt", 0, ifelse(e9 == "Resentment", 0, ifelse(e9 == "Disgust", 0, ifelse(e9 == "Disenchantment", 0, ifelse(e9 == "Irritation", 0, ifelse(e9 == "Fear", 0, ifelse(e9 == "Pain", 0, ifelse(e9 == "Surprise", 0, ifelse(e9 == "Calmness", 0, ifelse(e9 == "Affection", 0, ifelse(e9 == "Caring", 0, ifelse(e9 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e10_2 = ifelse(e10 == "Anger", 0, ifelse(e10 == "Sadness", 0, ifelse(e10 == "Optimism", 1, ifelse(e10 == "Nostalgia", 1, ifelse(e10 == "Hope", 1, ifelse(e10 == "Admiration", 1, ifelse(e10 == "Love", 1, ifelse(e10 == "Humiliation", 0, ifelse(e10 == "Guilt", 0, ifelse(e10 == "Resentment", 0, ifelse(e10 == "Disgust", 0, ifelse(e10 == "Disenchantment", 0, ifelse(e10 == "Irritation", 0, ifelse(e10 == "Fear", 0, ifelse(e10 == "Pain", 0, ifelse(e10 == "Surprise", 0, ifelse(e10 == "Calmness", 0, ifelse(e10 == "Affection", 0, ifelse(e10 == "Caring", 0, ifelse(e10 == "Desire", 0, NA))))))))))))))))))))) 
  
emotions_survey_text <- emotions_survey_text %>%
  mutate(positive_EmotionScore = rowSums(emotions_survey_text[,142:151]))


# Negative Secondary Emotions Score
emotions_survey_text <- emotions_survey_text %>%
  
  mutate(e2_3 = ifelse(e2 == "Anger", 0, ifelse(e2 == "Sadness", 0, ifelse(e2 == "Optimism", 0, ifelse(e2 == "Nostalgia", 0, ifelse(e2 == "Hope", 0, ifelse(e2 == "Admiration", 0, ifelse(e2 == "Love", 0, ifelse(e2 == "Humiliation", 1, ifelse(e2 == "Guilt", 1, ifelse(e2 == "Resentment", 1, ifelse(e2 == "Disgust", 1, ifelse(e2 == "Disenchantment", 1, ifelse(e2 == "Irritation", 0, ifelse(e2 == "Fear", 0, ifelse(e2 == "Pain", 0, ifelse(e2 == "Surprise", 0, ifelse(e2 == "Calmness", 0, ifelse(e2 == "Affection", 0, ifelse(e2 == "Caring", 0, ifelse(e2 == "Desire", 0, NA))))))))))))))))))))) %>% 
  
  mutate(e1_3 = ifelse(e1 == "Anger", 0, ifelse(e1 == "Sadness", 0, ifelse(e1 == "Optimism", 0, ifelse(e1 == "Nostalgia", 0, ifelse(e1 == "Hope", 0, ifelse(e1 == "Admiration", 0, ifelse(e1 == "Love", 0, ifelse(e1 == "Humiliation", 1, ifelse(e1 == "Guilt", 1, ifelse(e1 == "Resentment", 1, ifelse(e1 == "Disgust", 1, ifelse(e1 == "Disenchantment", 1, ifelse(e1 == "Irritation", 0, ifelse(e1 == "Fear", 0, ifelse(e1 == "Pain", 0, ifelse(e1 == "Surprise", 0, ifelse(e1 == "Calmness", 0, ifelse(e1 == "Affection", 0, ifelse(e1 == "Caring", 0, ifelse(e1 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e4_3 = ifelse(e4 == "Anger", 0, ifelse(e4 == "Sadness", 0, ifelse(e4 == "Optimism", 0, ifelse(e4 == "Nostalgia", 0, ifelse(e4 == "Hope", 0, ifelse(e4 == "Admiration", 0, ifelse(e4 == "Love", 0, ifelse(e4 == "Humiliation", 1, ifelse(e4 == "Guilt", 1, ifelse(e4 == "Resentment", 1, ifelse(e4 == "Disgust", 1, ifelse(e4 == "Disenchantment", 1, ifelse(e4 == "Irritation", 0, ifelse(e4 == "Fear", 0, ifelse(e4 == "Pain", 0, ifelse(e4 == "Surprise", 0, ifelse(e4 == "Calmness", 0, ifelse(e4 == "Affection", 0, ifelse(e4 == "Caring", 0, ifelse(e4 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e3_3 = ifelse(e3 == "Anger", 0, ifelse(e3 == "Sadness", 0, ifelse(e3 == "Optimism", 0, ifelse(e3 == "Nostalgia", 0, ifelse(e3 == "Hope", 0, ifelse(e3 == "Admiration", 0, ifelse(e3 == "Love", 0, ifelse(e3 == "Humiliation", 1, ifelse(e3 == "Guilt", 1, ifelse(e3 == "Resentment", 1, ifelse(e3 == "Disgust", 1, ifelse(e3 == "Disenchantment", 1, ifelse(e3 == "Irritation", 0, ifelse(e3 == "Fear", 0, ifelse(e3 == "Pain", 0, ifelse(e3 == "Surprise", 0, ifelse(e3 == "Calmness", 0, ifelse(e3 == "Affection", 0, ifelse(e3 == "Caring", 0, ifelse(e3 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e5_3 = ifelse(e5 == "Anger", 0, ifelse(e5 == "Sadness", 0, ifelse(e5 == "Optimism", 0, ifelse(e5 == "Nostalgia", 0, ifelse(e5 == "Hope", 0, ifelse(e5 == "Admiration", 0, ifelse(e5 == "Love", 0, ifelse(e5 == "Humiliation", 1, ifelse(e5 == "Guilt", 1, ifelse(e5 == "Resentment", 1, ifelse(e5 == "Disgust", 1, ifelse(e5 == "Disenchantment", 1, ifelse(e5 == "Irritation", 0, ifelse(e5 == "Fear", 0, ifelse(e5 == "Pain", 0, ifelse(e5 == "Surprise", 0, ifelse(e5 == "Calmness", 0, ifelse(e5 == "Affection", 0, ifelse(e5 == "Caring", 0, ifelse(e5 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e6_3 = ifelse(e6 == "Anger", 0, ifelse(e6 == "Sadness", 0, ifelse(e6 == "Optimism", 0, ifelse(e6 == "Nostalgia", 0, ifelse(e6 == "Hope", 0, ifelse(e6 == "Admiration", 0, ifelse(e6 == "Love", 0, ifelse(e6 == "Humiliation", 1, ifelse(e6 == "Guilt", 1, ifelse(e6 == "Resentment", 1, ifelse(e6 == "Disgust", 1, ifelse(e6 == "Disenchantment", 1, ifelse(e6 == "Irritation", 0, ifelse(e6 == "Fear", 0, ifelse(e6 == "Pain", 0, ifelse(e6 == "Surprise", 0, ifelse(e6 == "Calmness", 0, ifelse(e6 == "Affection", 0, ifelse(e6 == "Caring", 0, ifelse(e6 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e7_3 = ifelse(e7 == "Anger", 0, ifelse(e7 == "Sadness", 0, ifelse(e7 == "Optimism", 0, ifelse(e7 == "Nostalgia", 0, ifelse(e7 == "Hope", 0, ifelse(e7 == "Admiration", 0, ifelse(e7 == "Love", 0, ifelse(e7 == "Humiliation", 1, ifelse(e7 == "Guilt", 1, ifelse(e7 == "Resentment", 1, ifelse(e7 == "Disgust", 1, ifelse(e7 == "Disenchantment", 1, ifelse(e7 == "Irritation", 0, ifelse(e7 == "Fear", 0, ifelse(e7 == "Pain", 0, ifelse(e7 == "Surprise", 0, ifelse(e7 == "Calmness", 0, ifelse(e7 == "Affection", 0, ifelse(e7 == "Caring", 0, ifelse(e7 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e8_3 = ifelse(e8 == "Anger", 0, ifelse(e8 == "Sadness", 0, ifelse(e8 == "Optimism", 0, ifelse(e8 == "Nostalgia", 0, ifelse(e8 == "Hope", 0, ifelse(e8 == "Admiration", 0, ifelse(e8 == "Love", 0, ifelse(e8 == "Humiliation", 1, ifelse(e8 == "Guilt", 1, ifelse(e8 == "Resentment", 1, ifelse(e8 == "Disgust", 1, ifelse(e8 == "Disenchantment", 1, ifelse(e8 == "Irritation", 0, ifelse(e8 == "Fear", 0, ifelse(e8 == "Pain", 0, ifelse(e8 == "Surprise", 0, ifelse(e8 == "Calmness", 0, ifelse(e8 == "Affection", 0, ifelse(e8 == "Caring", 0, ifelse(e8 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e9_3 = ifelse(e9 == "Anger", 0, ifelse(e9 == "Sadness", 0, ifelse(e9 == "Optimism", 0, ifelse(e9 == "Nostalgia", 0, ifelse(e9 == "Hope", 0, ifelse(e9 == "Admiration", 0, ifelse(e9 == "Love", 0, ifelse(e9 == "Humiliation", 1, ifelse(e9 == "Guilt", 1, ifelse(e9 == "Resentment", 1, ifelse(e9 == "Disgust", 1, ifelse(e9 == "Disenchantment", 1, ifelse(e9 == "Irritation", 0, ifelse(e9 == "Fear", 0, ifelse(e9 == "Pain", 0, ifelse(e9 == "Surprise", 0, ifelse(e9 == "Calmness", 0, ifelse(e9 == "Affection", 0, ifelse(e9 == "Caring", 0, ifelse(e9 == "Desire", 0, NA))))))))))))))))))))) %>%
  
  mutate(e10_3 = ifelse(e10 == "Anger", 0, ifelse(e10 == "Sadness", 0, ifelse(e10 == "Optimism", 0, ifelse(e10 == "Nostalgia", 0, ifelse(e10 == "Hope", 0, ifelse(e10 == "Admiration", 0, ifelse(e10 == "Love", 0, ifelse(e10 == "Humiliation", 1, ifelse(e10 == "Guilt", 1, ifelse(e10 == "Resentment", 1, ifelse(e10 == "Disgust", 1, ifelse(e10 == "Disenchantment", 1, ifelse(e10 == "Irritation", 0, ifelse(e10 == "Fear", 0, ifelse(e10 == "Pain", 0, ifelse(e10 == "Surprise", 0, ifelse(e10 == "Calmness", 0, ifelse(e10 == "Affection", 0, ifelse(e10 == "Caring", 0, ifelse(e10 == "Desire", 0, NA))))))))))))))))))))) 
  
emotions_survey_text <- emotions_survey_text %>%
  mutate(negative_EmotionScore = rowSums(emotions_survey_text[,153:162]))


```


## Pairwise Subgroups 

```{r Subgroups}

# Make the 3 pairwise subgroups
plac_age_cond <- emotions_survey_text %>%
  filter(Condition < 2) # Placebo-Age Group 

age_vegi_cond <- emotions_survey_text %>%
  filter(Condition > 0) %>%
  mutate(Condition = ifelse(Condition == 1, 0, 1)) # Age-Vegi Group

plac_vegi_cond <- emotions_survey_text %>%
  filter(Condition == 0 | Condition == 2) %>%
  mutate(Condition = ifelse(Condition == 2, 1, 0)) # Placebo-Vegi Group

```

## Covariate Balance Checks
```{r, results = "asis", warning = F} 

# Pretreatment summary stats table with GTSummary

emotions_survey_balance <- emotions_survey_text %>% select(age, nationality, nat_id, gender, religion, relig_type, race, politics, combat1, combat2, confl_zone, Condition, IHLScore, followup2_1)


emotions_survey_balance %>% 
  tbl_summary(
    by = Condition, 
    type = c(age, IHLScore) ~ "continuous", 
    label = list(age ~ "Age", nationality ~ "Nationality", nat_id ~ "NatID", gender ~ "Gender", religion ~ "Religion", relig_type ~ "Religion Type", race ~ "Race", politics ~ "PolID", combat1 ~ "Combatant", combat2 ~ "CombExp", confl_zone ~ "ConflZone", followup2_1 ~ "Non-naivete"),
    statistic = list(all_continuous() ~ "{mean} ({sd})", all_categorical() ~ "{n} / {N} ({p}%)"), digits = all_continuous() ~ 2) %>% 
  add_overall() %>%
  add_n() %>%
  modify_header(label ~ "**Table OA.1: Descriptive Statistics**") %>%
  modify_spanning_header(c("stat_1", "stat_2", "stat_3") ~ "**Treatment Received**") %>%
  modify_footnote( 
    all_stat_cols() ~ "Mean (SD) or Frequency (%)"
    ) %>%
  bold_labels

# Balance Test using Multinomial Logistic Regression 

balance_test_multinom <- multinom(Condition ~ age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + followup2_1, data = emotions_survey_text) # including the pretreatment covariates and the non-naivete question
summary(balance_test_multinom)
stargazer(balance_test_multinom, align = T, type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, dep.var.labels = c("Condition 1", "Condition 2"), title = "Table OA.2: Balance Test Using Multinomial Logit", model.names = T, single.row = T) # shows balance with no significant relation between covariates and condition assignment

balance_test_ols <- lm(Condition ~ age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + followup2_1, data = emotions_survey_text)
stargazer(balance_test_ols, align = T, type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, dep.var.labels = "Condition", title = "Table OA.3: Balance Test Using OLS", model.names = T, single.row = T) # confirms multinomial finding with OLS showing no significant relation between covariates and condition assignment

## Generate p-value for multimonial model, using z-tests

z <- summary(balance_test_multinom)$coefficients/summary(balance_test_multinom)$standard.errors
z
p <- (1 - pnorm(abs(z), 0, 1))*2 # 2-tailed z test
p # p-values show insignificance for all covariates, demonstrating balance across Conditions


```


## Post-Treatment Summary Statistics Table

```{r Posttreat Stats Table, warning = F}


emotions_survey_posttreatment <- emotions_survey_text %>% select(duration, plac_timing, age_timing, vegi_timing, EmotionScore, MoralScore, percent1, percent2, percent3, percent4, percent5, percent6, followup2, followup3_1, Condition) 

emotions_survey_posttreatment %>% 
  tbl_summary(
    by = Condition, 
    missing = "no", 
    label = list(duration ~ "Survey Duration (Seconds)", plac_timing ~ "Placebo Prime Duration (Seconds)", age_timing ~ "Social Categorization Prime Duration (Seconds)", vegi_timing ~ "Mentalization Prime Duration (Seconds)", followup2 ~ "Non-naivete", followup3_1 ~ "Compliers", percent1 ~ "Domestic Charge", percent2 ~ "International Charge", percent3 ~ "Domestic Apprehension", percent4 ~ "International Apprehension", percent5 ~ "Domestic Conviction", percent6 ~ "International Conviction"),
    type = c(duration, plac_timing, age_timing, vegi_timing, EmotionScore, MoralScore, percent1, percent2, percent3, percent4, percent5, percent6) ~ "continuous", 
    statistic = list(all_continuous() ~ "{mean} ({sd})", all_categorical() ~ "{n} / {N} ({p}%)"), 
    digits = all_continuous() ~ 2) %>% 
  add_p() %>%
  add_overall() %>%
  add_n() %>%
  modify_header(label ~ "**Table OA.4: Post-Treatment Summary Statistics Table**") %>%
  modify_spanning_header(c("stat_1", "stat_2", "stat_3") ~ "**Treatment Received**") %>%
  modify_footnote( 
    all_stat_cols() ~ "Mean (sd) or Frequency (%)"
    ) %>%
  bold_labels

```

## H1-H3 Hypothesis Testing

### Effect of Prime on Emotions Score

```{r, results = "asis"} 

# Effect of Prime on Emotions Score

emotions_m1 <- lm(EmotionScore ~ Condition, data = plac_age_cond) # just Condition 
emotions_m2 <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

emotions_m3 <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = plac_age_cond) # Condition, covariates, and Combatant interaction

emotions_m4 <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = plac_age_cond) # Condition, covariates, and CombExp interaction

emotions_m5 <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = plac_age_cond) # Condition, covariates, and ConflZone interaction

emotions_m6 <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = plac_age_cond) # Condition, covariates, and IHLScore interaction

emotions_m7 <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = plac_age_cond) # Condition, covariates, and NatID interaction

emotions_m8 <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = plac_age_cond) # Condition, covariates, and PolID interaction

## Coefficient Table Stargazer

stargazer(emotions_m1, emotions_m2, emotions_m3, emotions_m4, emotions_m5, emotions_m6, emotions_m7, emotions_m8, align = T, dep.var.labels = "Emotions Score", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table 4.1: Effect of Violence Prime on Secondary Emotion Attribution", model.names = T, single.row = T)

mean(plac_age_cond$EmotionScore[plac_age_cond$Condition == 1]) - mean(plac_age_cond$EmotionScore[plac_age_cond$Condition == 0]) # double-check ATE with manual DiM

## Make Coefficient Plot

emotions_m2_names <- c("Constant", "Condition", "Age", "Nationality", "NatID", "Gender", "Religion", "Race", "PolID", "Combatant", "CombExp", "ConflZone", "IHLScore")
coefplot(emotions_m2, varnames = emotions_m2_names, main = "Figure OA.1: Effect of Violence Prime on Emotion Attribution (Model 2)")

# Robustness Checks

## Emotions P-values under the sharp null hypothesis
set.seed(103648)
emotions_Z <- plac_age_cond$Condition #treatment vector
emotions_Y <- plac_age_cond$EmotionScore #outcome vector
emotions_probs <- genprobexact(Z = emotions_Z)
emotions_ate <- estate(Y = emotions_Y, Z = emotions_Z, prob = emotions_probs)
emotions_ate #-0.1518663
emotions_perms <- genperms(emotions_Z, maxiter = 10000) #enumerate all possible ways of random assignment
emotions_Ys <- genouts(Y = emotions_Y, Z = emotions_Z, ate = 0) #generate full schedule of potential outcomes under exact H0, (ITT/ATE = 0)
emotions_distout <- gendist(emotions_Ys, emotions_perms, prob=emotions_probs) # generate randomization distribution 
emotions_dist <- dispdist(emotions_distout, emotions_ate)
emotions_abs_p <- mean(abs(emotions_distout) >= abs(emotions_ate)) #two-tailed test
emotions_abs_p #0.0328 p-value under sharp null hypothesis


## CACE for Placebo-age Group

### CACE Manually
plac_age_cond <- plac_age_cond %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))
itt <- lm(EmotionScore ~ Condition, data = plac_age_cond)
itt
ittd <- sum(plac_age_cond$followup_ittd)/sum(plac_age_cond$Condition)
ittd
cace <- itt$coefficients[2]/ittd
cace # CACE

### CACE with 2SLS

cace_iv_emotions <- ivreg(EmotionScore ~ followup_ittd, ~Condition, data = plac_age_cond)
stargazer(cace_iv_emotions, type = 'html', title = "Table OA.5: CACE of Prime on EmotionScore") 

## Robustness Check of Duration - ATE and CACE when taking away answers that are really fast (<=200s) or really slow (>=1200s)

plac_age_cond_duration <- plac_age_cond %>%
  filter(duration > 200) %>%
  filter(duration < 1200)
nrow(plac_age_cond_duration)
min(plac_age_cond_duration$duration)
max(plac_age_cond_duration$duration)

emotions_m1_dur <- lm(EmotionScore ~ Condition, data = plac_age_cond_duration) # just Condition 

emotions_m2_dur <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond_duration) # Condition and covariates

emotions_m3_dur <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = plac_age_cond_duration) # Condition, covariates, and Combatant interaction

emotions_m4_dur <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = plac_age_cond_duration) # Condition, covariates, and CombExp interaction

emotions_m5_dur <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = plac_age_cond_duration) # Condition, covariates, and ConflZone interaction

emotions_m6_dur <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = plac_age_cond_duration) # Condition, covariates, and IHLScore interaction

emotions_m7_dur <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = plac_age_cond_duration) # Condition, covariates, and NatID interaction

emotions_m8_dur <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = plac_age_cond_duration) # Condition, covariates, and PolID interaction

stargazer(emotions_m1_dur, emotions_m2_dur, emotions_m3_dur, emotions_m4_dur, emotions_m5_dur, emotions_m6_dur, emotions_m7_dur, emotions_m8_dur, align = T, dep.var.labels = "Emotions Score", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.6: Effect of Violence Prime on Emotion Attribution, Time-Limited", model.names = T, single.row = T)

mean(plac_age_cond_duration$EmotionScore[plac_age_cond_duration$Condition == 1]) - mean(plac_age_cond_duration$EmotionScore[plac_age_cond_duration$Condition == 0]) # double check ATE with manual DiM

coefplot(emotions_m2_dur, main = "Figure OA.2: Effect of Violence Prime on Secondary Emotion Attribution, Time-Limited")


plac_age_cond_duration <- plac_age_cond_duration %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))
cace_iv_dur <- ivreg(EmotionScore ~ followup_ittd, ~Condition, data = plac_age_cond_duration)
stargazer(cace_iv_dur, type = 'html', title = "Table OA.7: CACE of Prime on EmotionScore, Time-Limited") 


## Robustness Check for Non-naivete

emotions_followup <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + followup2_1, data = plac_age_cond) # Condition and covariates, plus non-naivete question
stargazer(emotions_followup, type = 'html', title = "Table OA.8: Robustness Check for Non-naivete on Emotions Score") 

## Checking Infrahumanization Independent from Valence

### Run same hypothesis tests for positive_EmotionScore

emotions_m1_pos <- lm(positive_EmotionScore ~ Condition, data = plac_age_cond) # just Condition IV

emotions_m2_pos <- lm(positive_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

emotions_m3_pos <- lm(positive_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = plac_age_cond) # Condition, covariates, and Combatant interaction

emotions_m4_pos <- lm(positive_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = plac_age_cond) # Condition, covariates, and CombExp interaction

emotions_m5_pos <- lm(positive_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = plac_age_cond) # Condition, covariates, and ConflZone interaction

emotions_m6_pos <- lm(positive_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = plac_age_cond) # Condition, covariates, and IHLScore interaction

emotions_m7_pos <- lm(positive_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = plac_age_cond) # Condition, covariates, and NatID interaction

emotions_m8_pos <- lm(positive_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = plac_age_cond) # Condition, covariates, and PolID interaction

stargazer(emotions_m1_pos, emotions_m2_pos, emotions_m3_pos, emotions_m4_pos, emotions_m5_pos, emotions_m6_pos, emotions_m7_pos, emotions_m8_pos, align = T, dep.var.labels = "Positive Emotions Score", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.9: Effect of Violence Prime on Positive Secondary Emotion Attribution", model.names = T, single.row = T)

coefplot(emotions_m2_pos, main = "Figure OA.3: Effect of Violence Prime on Positive Secondary Emotion Attribution")

cace_iv_pos <- ivreg(positive_EmotionScore ~ followup_ittd, ~Condition, data = plac_age_cond)
stargazer(cace_iv_pos, type = 'html', title = "Table OA.10: CACE of Prime on Positive Secondary Emotion Attribution") 

### Run same hypothesis tests for negative_EmotionScore 

emotions_m1_neg <- lm(negative_EmotionScore ~ Condition, data = plac_age_cond) # just Condition 

emotions_m2_neg <- lm(negative_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

emotions_m3_neg <- lm(negative_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = plac_age_cond) # Condition, covariates, and Combatant interaction

emotions_m4_neg <- lm(negative_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = plac_age_cond) # Condition, covariates, and CombExp interaction

emotions_m5_neg <- lm(negative_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = plac_age_cond) # Condition, covariates, and ConflZone interaction

emotions_m6_neg <- lm(negative_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = plac_age_cond) # Condition, covariates, and IHLScore interaction

emotions_m7_neg <- lm(negative_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = plac_age_cond) # Condition, covariates, and NatID interaction

emotions_m8_neg <- lm(negative_EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = plac_age_cond) # Condition, covariates, and PolID interaction

stargazer(emotions_m1_neg, emotions_m2_neg, emotions_m3_neg, emotions_m4_neg, emotions_m5_neg, emotions_m6_neg, emotions_m7_neg, emotions_m8_neg, align = T, dep.var.labels = "Negative Emotions Score", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.11: Effect of Violence Prime on Negative Secondary Emotion Attribution", model.names = T, single.row = T)

mean(plac_age_cond$negative_EmotionScore[plac_age_cond$Condition == 1]) - mean(plac_age_cond$negative_EmotionScore[plac_age_cond$Condition == 0]) # double check ATE with manual DiM

coefplot(emotions_m2_neg, main = "Figure OA.4: Effect of Violence Prime on Negative Secondary Emotion Attribution")

cace_iv_neg <- ivreg(negative_EmotionScore ~ followup_ittd, ~Condition, data = plac_age_cond)
stargazer(cace_iv_neg, type = 'html', title = "Table OA.12: CACE of Prime on Negative Secondary Emotion Attribution") 

```


### Effect of Prime on Morals Score

```{r, results = "asis"} 
# Effect of Prime on Morals Score

morals_m1 <- lm(MoralScore ~ Condition, data = plac_age_cond) # just Condition 

morals_m2 <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

morals_m3 <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = plac_age_cond) # Condition, covariates, and Combatant interaction

morals_m4 <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = plac_age_cond) # Condition, covariates, and CombExp interaction

morals_m5 <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = plac_age_cond) # Condition, covariates, and ConflZone interaction

morals_m6 <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = plac_age_cond) # Condition, covariates, and IHLScore interaction

morals_m7 <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = plac_age_cond) # Condition, covariates, and NatID interaction

morals_m8 <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = plac_age_cond) # Condition, covariates, and PolID interaction

## Coefficient Table Stargazer

stargazer(morals_m1, morals_m2, morals_m3, morals_m4, morals_m5, morals_m6, morals_m7, morals_m8, align = T, dep.var.labels = "Morals Score", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table 4.2: Effect of Violence Prime on Moral Exclusion", model.names = T, single.row = T)

mean(plac_age_cond$MoralScore[plac_age_cond$Condition == 1]) - mean(plac_age_cond$MoralScore[plac_age_cond$Condition == 0]) # double check ate with manual DiM

## Make coefficient plot

morals_m2_names <- c("Constant", "Condition", "Age", "Nationality", "NatID", "Gender", "Religion", "Race", "PolID", "Combatant", "CombExp", "ConflZone", "IHLScore")

coefplot(morals_m2, varnames = morals_m2_names, main = "Effect of Violence Prime on Moral Exclusion (Model 2)")

# Robustness Checks

## Morals P-value under the sharp null hypothesis

set.seed(103648)
morals_Z <- plac_age_cond$Condition #treatment vector
morals_Y <- plac_age_cond$MoralScore #outcome vector
morals_probs <- genprobexact(Z = morals_Z)
morals_ate <- estate(Y = morals_Y, Z = morals_Z, prob = morals_probs)
morals_ate #0.1035451
morals_perms <- genperms(morals_Z, maxiter = 10000) #enumerate all possible ways of random assignment
morals_Ys <- genouts(Y = morals_Y, Z = morals_Z, ate = 0) #generate full schedule of potential outcomes under exact H0, (ITT/ATE = 0)
morals_distout <- gendist(morals_Ys, morals_perms, prob=morals_probs) # generate randomization distribution 
morals_dist <- dispdist(morals_distout, morals_ate)
morals_abs_p <- mean(abs(morals_distout) >= abs(morals_ate)) #two-tailed test
morals_abs_p #0.3488 p-value under sharp null hypothesis, insignificant

## CACE for Placebo-age Group

plac_age_cond <- plac_age_cond %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))

cace_iv_morals <- ivreg(MoralScore ~ followup_ittd, ~Condition, data = plac_age_cond)
stargazer(cace_iv_morals, type = 'html', title = "Table OA.13: CACE of Prime on Moral Score") 


## Robustness Check of Duration - ATE and CACE when taking away answers that are really fast (<=200s) or really slow (>=1200s)

plac_age_cond_duration <- plac_age_cond %>%
  filter(duration > 200) %>%
  filter(duration < 1200)
nrow(plac_age_cond_duration)
min(plac_age_cond_duration$duration)
max(plac_age_cond_duration$duration)

morals_m1_dur <- lm(MoralScore ~ Condition, data = plac_age_cond_duration) # just Condition IV

morals_m2_dur <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond_duration) # Condition and covariates

morals_m3_dur <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = plac_age_cond_duration) # Condition, covariates, and Combatant interaction

morals_m4_dur <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = plac_age_cond_duration) # Condition, covariates, and CombExp interaction

morals_m5_dur <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = plac_age_cond_duration) # Condition, covariates, and ConflZone interaction

morals_m6_dur <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = plac_age_cond_duration) # Condition, covariates, and IHLScore interaction

morals_m7_dur <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = plac_age_cond_duration) # Condition, covariates, and NatID interaction

morals_m8_dur <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = plac_age_cond_duration) # Condition, covariates, and PolID interaction

stargazer(morals_m1_dur, morals_m2_dur, morals_m3_dur, morals_m4_dur, morals_m5_dur, morals_m6_dur, morals_m7_dur, morals_m8_dur, align = T, dep.var.labels = "Morals Score", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.14: Effect of Violence Prime on Morals Score, Time-Limited", model.names = T, single.row = T)

coefplot(morals_m2_dur, main = "Figure OA.5: Effect of Violence Prime on Morals Score, Time-Limited")

plac_age_cond_duration <- plac_age_cond_duration %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))
cace_iv_morals_dur <- ivreg(MoralScore ~ followup_ittd, ~Condition, data = plac_age_cond_duration)
stargazer(cace_iv_morals_dur, type = 'html', title = "Table OA.15: CACE of Prime on Morals Score, Time-Limited") 

## Robustness Check for Non-naivete

morals_followup <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + followup2_1, data = plac_age_cond) # Condition and covariates, plus non-naivete question
stargazer(morals_followup, type = 'html', title = "Table OA.16: Robustness Check for Non-naivete on Moral Score") 

## Mediation Effects - No significant mediation effects

### Mediation of effect of Condition (X) on Morals Score (Y) by Emotions Score (M), Without Time Limit
med.fit.morals <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond)
out.fit.morals <- lm(MoralScore ~ EmotionScore + Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond)
med.out.morals <- mediate(med.fit.morals, out.fit.morals, treat = "Condition", mediator = "EmotionScore", robustSE = T, sims = 1000)
summary(med.out.morals) # no significant mediation effects (ACME)
plot(med.out.morals, main = "Figure OA.6: ACME of EmotionScore on MoralScore") # plot the mediation effects

### Mediation of effect of Condition (X) on Morals Score (Y) by Emotions Score (M), With Time Limit
med.fit.morals.dur <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond_duration)
out.fit.morals.dur <- lm(MoralScore ~ EmotionScore + Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond_duration)
med.out.morals.dur <- mediate(med.fit.morals.dur, out.fit.morals.dur, treat = "Condition", mediator = "EmotionScore", robustSE = T, sims = 1000)
summary(med.out.morals.dur) # no significant mediation effects
plot(med.out.morals.dur, main = "Figure OA.7: ACME of EmotionScore, Time-Limited")
```


### Effect of Prime on Probability Estimates

```{r,  results = "asis"} 
# Effect of Prime on 6 Percents Estimates 

percents1_m1 <- lm(percent1 ~ Condition, data = plac_age_cond) # just Condition 

percents1_m2 <- lm(percent1 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

percents2_m1 <- lm(percent2 ~ Condition, data = plac_age_cond) # just Condition IV

percents2_m2 <- lm(percent2 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

percents3_m1 <- lm(percent3 ~ Condition, data = plac_age_cond) # just Condition IV

percents3_m2 <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

percents4_m1 <- lm(percent4 ~ Condition, data = plac_age_cond) # just Condition IV

percents4_m2 <- lm(percent4 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

percents5_m1 <- lm(percent5 ~ Condition, data = plac_age_cond) # just Condition IV

percents5_m2 <- lm(percent5 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

percents6_m1 <- lm(percent6 ~ Condition, data = plac_age_cond) # just Condition IV

percents6_m2 <- lm(percent6 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

## Coefficient Table Stargazer

stargazer(percents1_m1, percents1_m2, percents2_m1, percents2_m2, percents3_m1,  percents3_m2, percents4_m1, percents4_m2, percents5_m1, percents5_m2, percents6_m1, percents6_m2, align = T, dep.var.labels = c("Domestic Charge (πI)", "International Charge (πI)", "Domestic Apprehension (πA|I)", "International Apprehension (πA|I)", "Domestic Conviction (πC|A|I)", "International Conviction (πC|A|I)"), type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table 4.3: Effect of Violence Prime on Sanction Risk Perceptions", model.names = T, single.row = T)

# Effect of Prime on Domestic Apprehension Risk Perception

percents3_m1 <- lm(percent3 ~ Condition, data = plac_age_cond) # just Condition 

percents3_m2 <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond) # Condition and covariates

percents3_m3 <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = plac_age_cond) # Condition, covariates, and Combatant interaction

percents3_m4 <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = plac_age_cond) # Condition, covariates, and CombExp interaction

percents3_m5 <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = plac_age_cond) # Condition, covariates, and ConflZone interaction

percents3_m6 <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = plac_age_cond) # Condition, covariates, and IHLScore interaction

percents3_m7 <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = plac_age_cond) # Condition, covariates, and NatID interaction

percents3_m8 <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = plac_age_cond) # Condition, covariates, and PolID interaction

stargazer(percents3_m1, percents3_m2, percents3_m3, percents3_m4, percents3_m5, percents3_m6, percents3_m7, percents3_m8, align = T, dep.var.labels = "Domestic Apprehension", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.17: Effect of Violence Prime on Domestic Apprehension Risk Perception", model.names = T, single.row = T)

mean(plac_age_cond$percent3[plac_age_cond$Condition == 1]) - mean(plac_age_cond$percent3[plac_age_cond$Condition == 0]) # double-check ATE with manual DiM

coefplot(percents3_m2, main = "Figure OA.8: Effect of Violence Prime on Domestic Apprehension Risk Perception")

# Robustness Checks

## Morals P-value under the sharp null hypothesis

set.seed(103648)
percent3_Z <- plac_age_cond$Condition #treatment vector
percent3_Y <- plac_age_cond$percent3 #outcome vector
percent3_probs <- genprobexact(Z = percent3_Z)
percent3_ate <- estate(Y = percent3_Y, Z = percent3_Z, prob = percent3_probs)
percent3_ate #-3.71584
percent3_perms <- genperms(percent3_Z, maxiter = 10000) #enumerate all possible ways of random assignment
percent3_Ys <- genouts(Y = percent3_Y, Z = percent3_Z, ate = 0) #generate full schedule of potential outcomes under exact H0, (ITT/ATE = 0)
percent3_distout <- gendist(percent3_Ys, percent3_perms, prob=percent3_probs) # generate randomization distribution 
percent3_dist <- dispdist(percent3_distout, percent3_ate)
percent3_abs_p <- mean(abs(percent3_distout) >= abs(percent3_ate)) #two-tailed test
percent3_abs_p #0.0849 p-value under sharp null hypothesis


## CACE for Placebo-age Group

plac_age_cond <- plac_age_cond %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))

cace_iv_percent1 <- ivreg(percent1 ~ followup_ittd, ~Condition, data = plac_age_cond)

cace_iv_percent2 <- ivreg(percent2 ~ followup_ittd, ~Condition, data = plac_age_cond)

cace_iv_percent3 <- ivreg(percent3 ~ followup_ittd, ~Condition, data = plac_age_cond)

cace_iv_percent4<- ivreg(percent4 ~ followup_ittd, ~Condition, data = plac_age_cond)

cace_iv_percent5 <- ivreg(percent5 ~ followup_ittd, ~Condition, data = plac_age_cond)

cace_iv_percent6 <- ivreg(percent6 ~ followup_ittd, ~Condition, data = plac_age_cond)

stargazer(cace_iv_percent1, cace_iv_percent2, cace_iv_percent3, cace_iv_percent4, cace_iv_percent5, cace_iv_percent6, type = 'html', title = "Table OA.18: CACE of Prime on Charge, Apprehension and Conviction Estimates") 

## Robustness Check of Duration - ATE and CACE when taking away answers that are really fast (<=200s) or really slow (>=1200s)

plac_age_cond_duration <- plac_age_cond %>%
  filter(duration > 200) %>%
  filter(duration < 1200)
nrow(plac_age_cond_duration)
min(plac_age_cond_duration$duration)
max(plac_age_cond_duration$duration)

percent3_m1_dur <- lm(percent3 ~ Condition, data = plac_age_cond_duration) # just Condition IV

percent3_m2_dur <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond_duration) # Condition and covariates

percent3_m3_dur <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = plac_age_cond_duration) # Condition, covariates, and Combatant interaction

percent3_m4_dur <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = plac_age_cond_duration) # Condition, covariates, and CombExp interaction

percent3_m5_dur <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = plac_age_cond_duration) # Condition, covariates, and ConflZone interaction

percent3_m6_dur <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = plac_age_cond_duration) # Condition, covariates, and IHLScore interaction

percent3_m7_dur <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = plac_age_cond_duration) # Condition, covariates, and NatID interaction

percent3_m8_dur <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = plac_age_cond_duration) # Condition, covariates, and PolID interaction

stargazer(percent3_m1_dur, percent3_m2_dur, percent3_m3_dur, percent3_m4_dur, percent3_m5_dur, percent3_m6_dur, percent3_m7_dur, percent3_m8_dur, align = T, dep.var.labels = "Domestic Apprehension", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.19: Effect of Violence Prime on Domestic Apprehension, Time-Limited", model.names = T, single.row = T)

coefplot(percent3_m2_dur, main = "Figure OA.9: Effect of Violence Prime on Domestic Apprehension, Time-Limited")

percents1_m1_dur <- lm(percent1 ~ Condition, data = plac_age_cond_duration) # just Condition IV

percents2_m1_dur <- lm(percent2 ~ Condition, data = plac_age_cond_duration) # just Condition IV

percents3_m1_dur <- lm(percent3 ~ Condition, data = plac_age_cond_duration) # just Condition IV

percents4_m1_dur <- lm(percent4 ~ Condition, data = plac_age_cond_duration) # just Condition IV

percents5_m1_dur <- lm(percent5 ~ Condition, data = plac_age_cond_duration) # just Condition IV

percents6_m1_dur <- lm(percent6 ~ Condition, data = plac_age_cond_duration) # just Condition IV

stargazer(percents1_m1_dur, percents2_m1_dur, percents3_m1_dur,  percents4_m1_dur, percents5_m1_dur, percents6_m1_dur, align = T, dep.var.labels = c("Domestic Charge", "International Charge", "Domestic Apprehension", "International Apprehension", "Domestic Conviction", "International Conviction"), type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.20: Effect of Violence Prime on Charge,  Apprehension and Conviction Estimates, Time-Limited", model.names = T, single.row = T)

plac_age_cond_duration <- plac_age_cond_duration %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))

cace_iv_percent1_dur <- ivreg(percent1 ~ followup_ittd, ~Condition, data = plac_age_cond_duration)

cace_iv_percent2_dur <- ivreg(percent2 ~ followup_ittd, ~Condition, data = plac_age_cond_duration)

cace_iv_percent3_dur <- ivreg(percent3 ~ followup_ittd, ~Condition, data = plac_age_cond_duration)

cace_iv_percent4_dur <- ivreg(percent4 ~ followup_ittd, ~Condition, data = plac_age_cond_duration)

cace_iv_percent5_dur <- ivreg(percent5 ~ followup_ittd, ~Condition, data = plac_age_cond_duration)

cace_iv_percent6_dur <- ivreg(percent6 ~ followup_ittd, ~Condition, data = plac_age_cond_duration)

stargazer(cace_iv_percent1_dur, cace_iv_percent2_dur, cace_iv_percent3_dur, cace_iv_percent4_dur, cace_iv_percent5_dur, cace_iv_percent6_dur, type = 'html', title = "Table OA.21: CACE of Prime on Charge, Apprehension and Conviction Estimates, Time-Limited") 


## Robustness Check for Non-naivete

percent3_followup <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + followup2_1, data = plac_age_cond) # Condition and covariates, plus non-naivete question
stargazer(percent3_followup, type = 'html', title = "Table OA.22: Robustness Check for Non-naivete on Domestic Apprehension Risk Perception") 

# Mediation Effects

## Single Mediation of effect of Condition (X) on percent3 (Y) by Emotions Score (M)
med.fit.percent3 <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond)
out.fit.percent3 <- lm(percent3 ~ EmotionScore + Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond)
med.out.percent3 <- mediate(med.fit.percent3, out.fit.percent3, treat = "Condition", mediator = "EmotionScore", robustSE = T, sims = 1000)
summary(med.out.percent3) # mediation effect not significant (ACME), the direct effect (ADE) of the Condition on the percent3 is not significant
plot(med.out.percent3, main = "Figure OA.10: ACME of EmotionScore on Percent3")

## Single Mediation of effect of Condition (X) on percent3 (Y) by Morals Score (M)
med.fit2.percent3 <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond)
out.fit2.percent3 <- lm(percent3 ~ MoralScore + Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = plac_age_cond)
med.out2.percent3 <- mediate(med.fit2.percent3, out.fit2.percent3, treat = "Condition", mediator = "MoralScore", robustSE = T, sims = 1000)
summary(med.out2.percent3) # the direct effect (ADE) of the Condition on percent3 is not significant, the mediation effect (ACME) is also not significant
plot(med.out2.percent3, main = "Figure OA.11: ACME of MoralScore on Percent3")

```

## Mentalization Hypothesis Testing (H4)

### Effect of Mentalization on Emotions Score

```{r, results = "asis"} 

# Effect of Mentalization on Emotions Score, 8 OLS Models - None are significant

emotions_m1_av <- lm(EmotionScore ~ Condition, data = age_vegi_cond) # just Condition IV

emotions_m2_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond) # Condition and covariates

emotions_m3_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = age_vegi_cond) # Condition, covariates, and Combatant interaction

emotions_m4_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = age_vegi_cond) # Condition, covariates, and CombExp interaction

emotions_m5_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = age_vegi_cond) # Condition, covariates, and ConflZone interaction

emotions_m6_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = age_vegi_cond) # Condition, covariates, and IHLScore interaction

emotions_m7_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = age_vegi_cond) # Condition, covariates, and NatID interaction

emotions_m8_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = age_vegi_cond) # Condition, covariates, and PolID interaction

## Coefficient Table Stargazer

stargazer(emotions_m1_av, emotions_m2_av, emotions_m3_av, emotions_m4_av, emotions_m5_av, emotions_m6_av, emotions_m7_av, emotions_m8_av, align = T, dep.var.labels = "Emotions Score", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.23: Effect of Mentalization on Secondary Emotion Attribution", model.names = T, single.row = T)

coefplot(emotions_m2_av, main = "Figure OA.12: Effect of Mentalization on Secondary Emotion Attribution")

# Robustness Checks

## Emotions P-values under the sharp null hypothesis
set.seed(103648)
emotions_Z_av <- age_vegi_cond$Condition #treatment vector
emotions_Y_av <- age_vegi_cond$EmotionScore #outcome vector
emotions_probs_av <- genprobexact(Z = emotions_Z_av)
emotions_ate_av <- estate(Y = emotions_Y_av, Z = emotions_Z_av, prob = emotions_probs_av)
emotions_ate_av #-0.005459408
emotions_perms_av <- genperms(emotions_Z_av, maxiter = 10000) #enumerate all possible ways of random assignment
emotions_Ys_av <- genouts(Y = emotions_Y_av, Z = emotions_Z_av, ate = 0) #generate full schedule of potential outcomes under exact H0, (ITT/ATE = 0)
emotions_distout_av <- gendist(emotions_Ys_av, emotions_perms_av, prob=emotions_probs_av) # generate randomization distribution 
emotions_dist_av <- dispdist(emotions_distout_av, emotions_ate_av)
emotions_abs_p_av <- mean(abs(emotions_distout_av) >= abs(emotions_ate_av)) #two-tailed test
emotions_abs_p_av #0.969 p-value

## CACE for Age-Vegi Group

age_vegi_cond <- age_vegi_cond %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))

cace_iv_emotions_av <- ivreg(EmotionScore ~ followup_ittd, ~Condition, data = age_vegi_cond)
stargazer(cace_iv_emotions_av, type = 'html', title = "Table OA.24: CACE of Mentalization on Secondary Emotion Attribution") # CACE Insignificant

## Robustness Check of Duration - ATE and CACE when taking away answers that are really fast (<=200s) or really slow (>=1200s)

age_vegi_cond_duration <- age_vegi_cond %>%
  filter(duration > 200) %>%
  filter(duration < 1200)
nrow(age_vegi_cond_duration)
min(age_vegi_cond_duration$duration)
max(age_vegi_cond_duration$duration)

emotions_m1_dur_av <- lm(EmotionScore ~ Condition, data = age_vegi_cond_duration) # just Condition IV

emotions_m2_dur_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond_duration) # Condition and covariates

emotions_m3_dur_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = age_vegi_cond_duration) # Condition, covariates, and Combatant interaction

emotions_m4_dur_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = age_vegi_cond_duration) # Condition, covariates, and CombExp interaction

emotions_m5_dur_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = age_vegi_cond_duration) # Condition, covariates, and ConflZone interaction

emotions_m6_dur_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = age_vegi_cond_duration) # Condition, covariates, and IHLScore interaction

emotions_m7_dur_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = age_vegi_cond_duration) # Condition, covariates, and NatID interaction

emotions_m8_dur_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = age_vegi_cond_duration) # Condition, covariates, and PolID interaction

stargazer(emotions_m1_dur_av, emotions_m2_dur_av, emotions_m3_dur_av, emotions_m4_dur_av, emotions_m5_dur_av, emotions_m6_dur_av, emotions_m7_dur_av, emotions_m8_dur_av, align = T, dep.var.labels = "Emotions Score", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.25: Effect of Mentalization on Secondary Emotion Attribution, Time-Limited", model.names = T, single.row = T)

coefplot(emotions_m2_dur_av, main = "Figure OA.13: Effect of Mentalization on Secondary Emotion Attribution, Time-Limited")

age_vegi_cond_duration <- age_vegi_cond_duration %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))
cace_iv_dur_av <- ivreg(EmotionScore ~ followup_ittd, ~Condition, data = age_vegi_cond_duration)
stargazer(cace_iv_dur_av, type = 'html', title = "Table OA.26: CACE of Mentalization on Secondary Emotion Attribution, Time-Limited") 

## Robustness Check for Non-naivete

emotions_followup_av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + followup2_1, data = age_vegi_cond) # Condition and covariates, plus non-naivete question
stargazer(emotions_followup_av, type = 'html', title = "Table OA.27: Robustness Check for Non-naivete on Emotions Attribution, Mentalization Condition") 

```


### Effect of Mentalization on Morals Score

```{r,  results = "asis"} 
# Effect of Mentalization on Morals Score

morals_m1_av <- lm(MoralScore ~ Condition, data = age_vegi_cond) # just Condition 

morals_m2_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond) # Condition and covariates

morals_m3_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = age_vegi_cond) # Condition, covariates, and Combatant interaction

morals_m4_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = age_vegi_cond) # Condition, covariates, and CombExp interaction

morals_m5_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = age_vegi_cond) # Condition, covariates, and ConflZone interaction

morals_m6_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = age_vegi_cond) # Condition, covariates, and IHLScore interaction

morals_m7_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = age_vegi_cond) # Condition, covariates, and NatID interaction

morals_m8_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = age_vegi_cond) # Condition, covariates, and PolID interaction

## Coefficient Table Stargazer

stargazer(morals_m1_av, morals_m2_av, morals_m3_av, morals_m4_av, morals_m5_av, morals_m6_av, morals_m7_av, morals_m8_av, align = T, dep.var.labels = "Morals Score", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.28: Effect of Mentalization on Morals Score", model.names = T, single.row = T) # significant negative impact

coefplot(morals_m2_av, main = "Figure OA.14: Effect of Mentalization on Morals Score")

# Robustness Checks

## Morals P-value under the sharp null hypothesis

set.seed(103648)
morals_Z_av <- age_vegi_cond$Condition #treatment vector
morals_Y_av <- age_vegi_cond$MoralScore #outcome vector
morals_probs_av <- genprobexact(Z = morals_Z_av)
morals_ate_av <- estate(Y = morals_Y_av, Z = morals_Z_av, prob = morals_probs_av)
morals_ate_av #-0.101778
morals_perms_av <- genperms(morals_Z_av, maxiter = 10000) #enumerate all possible ways of random assignment
morals_Ys_av <- genouts(Y = morals_Y_av, Z = morals_Z_av, ate = 0) #generate full schedule of potential outcomes under exact H0, (ITT/ATE = 0)
morals_distout_av <- gendist(morals_Ys_av, morals_perms_av, prob=morals_probs_av) # generate randomization distribution 
morals_dist_av <- dispdist(morals_distout_av, morals_ate_av)
morals_abs_p_av <- mean(abs(morals_distout_av) >= abs(morals_ate_av)) #two-tailed test
morals_abs_p_av #0.3545 p-value


## CACE for age-Vegi Group

age_vegi_cond <- age_vegi_cond %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))

cace_iv_morals_av <- ivreg(MoralScore ~ followup_ittd, ~Condition, data = age_vegi_cond)
stargazer(cace_iv_morals_av, type = 'html', title = "Table OA.29: CACE of Mentalization on Morals Score") 

## Robustness Check of Duration - ATE and CACE when taking away answers that are really fast (<=200s) or really slow (>=1200s)

morals_m1_dur_av <- lm(MoralScore ~ Condition, data = age_vegi_cond_duration) # just Condition IV

morals_m2_dur_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond_duration) # Condition and covariates

morals_m3_dur_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*Combatant, data = age_vegi_cond_duration) # Condition, covariates, and Combatant interaction

morals_m4_dur_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*CombExp, data = age_vegi_cond_duration) # Condition, covariates, and CombExp interaction

morals_m5_dur_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*ConflZone, data = age_vegi_cond_duration) # Condition, covariates, and ConflZone interaction

morals_m6_dur_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*IHLScore, data = age_vegi_cond_duration) # Condition, covariates, and IHLScore interaction

morals_m7_dur_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*NatID, data = age_vegi_cond_duration) # Condition, covariates, and NatID interaction

morals_m8_dur_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + Condition*PolID, data = age_vegi_cond_duration) # Condition, covariates, and PolID interaction

stargazer(morals_m1_dur_av, morals_m2_dur_av, morals_m3_dur_av, morals_m4_dur_av, morals_m5_dur_av, morals_m6_dur_av, morals_m7_dur_av, morals_m8_dur_av, align = T, dep.var.labels = "Morals Score", type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.30: Effect of Mentalization on Morals Score, Time-Limited", model.names = T, single.row = T) 

coefplot(morals_m2_dur_av, main = "Figure OA.15: Effect of Mentalization on Morals Score, Time-Limited")

age_vegi_cond_duration <- age_vegi_cond_duration %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))
cace_iv_morals_dur_av <- ivreg(MoralScore ~ followup_ittd, ~Condition, data = age_vegi_cond_duration)
stargazer(cace_iv_morals_dur_av, type = 'html', title = "Table OA.31: CACE of Mentalization on Morals Score, Time-Limited") 


## Robustness Check for Non-naivete

morals_followup_av <- lm(MoralScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + followup2_1, data = age_vegi_cond) # Condition and covariates, plus non-naivete question
stargazer(morals_followup_av, type = 'html', title = "Table OA.32: Robustness Check for Non-naivete on Morals Score, Mentalization Condition") 


## Mediation Effects - No significant mediation effects

### Mediation of effect of Condition on Morals Score by Emotions Score, Without Time Limit
med.fit.morals.av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond)
out.fit.morals.av <- lm(MoralScore ~ EmotionScore + Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond)
med.out.morals.av <- mediate(med.fit.morals.av, out.fit.morals.av, treat = "Condition", mediator = "EmotionScore", robustSE = T, sims = 1000)
summary(med.out.morals.av) # no significant mediation effects (ACME), yes significant negative direct effects (ADE)
plot(med.out.morals.av, main = "Figure OA.16: ACME of EmotionScore on MoralScore") # plot the mediation effects

### Mediation of effect of Condition on Morals Score by Emotions Score, With Time Limit
med.fit.morals.dur.av <- lm(EmotionScore ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond_duration)
out.fit.morals.dur.av <- lm(MoralScore ~ EmotionScore + Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond_duration)
med.out.morals.dur.av <- mediate(med.fit.morals.dur.av, out.fit.morals.dur.av, treat = "Condition", mediator = "EmotionScore", robustSE = T, sims = 1000)
summary(med.out.morals.dur.av) # no significant mediation effects (ACME), yes significant negative direct effects (ADE)
plot(med.out.morals.dur.av, main = "Figure OA.17: ACME of EmotionScore on MoralScore, Time-Limited")

```


### Effect of Mentalization on Probability Estimates

```{r, results = "asis"} 
# Effect of Mentalization on 6 Probability Estimates 

percents1_m1_av <- lm(percent1 ~ Condition, data = age_vegi_cond) # just Condition IV

percents1_m2_av <- lm(percent1 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond) # Condition and covariates

percents2_m1_av <- lm(percent2 ~ Condition, data = age_vegi_cond) # just Condition IV

percents2_m2_av <- lm(percent2 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond) # Condition and covariates

percents3_m1_av <- lm(percent3 ~ Condition, data = age_vegi_cond) # just Condition IV

percents3_m2_av <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond) # Condition and covariates

percents4_m1_av <- lm(percent4 ~ Condition, data = age_vegi_cond) # just Condition IV

percents4_m2_av <- lm(percent4 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond) # Condition and covariates

percents5_m1_av <- lm(percent5 ~ Condition, data = age_vegi_cond) # just Condition IV

percents5_m2_av <- lm(percent5 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond) # Condition and covariates

percents6_m1_av <- lm(percent6 ~ Condition, data = age_vegi_cond) # just Condition IV

percents6_m2_av <- lm(percent6 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore, data = age_vegi_cond) # Condition and covariates

## Coefficient Table Stargazer

stargazer(percents1_m1_av, percents1_m2_av, percents2_m1_av, percents2_m2_av, percents3_m1_av,  percents3_m2_av, percents4_m1_av, percents4_m2_av, align = T, dep.var.labels = c("Domestic Charge", "International Charge", "Domestic Apprehension", "International Apprehension"), type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.33: Effect of Mentalization on Charge and  Apprehension  Estimates", model.names = T, single.row = T) # no significant effects

stargazer(percents5_m1_av, percents5_m2_av, percents6_m1_av, percents6_m2_av, align = T, dep.var.labels = c("Domestic Conviction", "International Conviction"),type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.34: Effect of Mentalization on  Conviction Estimates", model.names = T, single.row = T) # no significant effects

# Robustness Checks

## Robustness Check of Duration - ATE and CACE when taking away answers that are really fast (<=200s) or really slow (>=1200s); 

### Duration ATE 

percents1_m1_dur_av <- lm(percent1 ~ Condition, data = age_vegi_cond_duration) # just Condition IV

percents2_m1_dur_av <- lm(percent2 ~ Condition, data = age_vegi_cond_duration) # just Condition IV

percents3_m1_dur_av <- lm(percent3 ~ Condition, data = age_vegi_cond_duration) # just Condition IV

percents4_m1_dur_av <- lm(percent4 ~ Condition, data = age_vegi_cond_duration) # just Condition IV

percents5_m1_dur_av <- lm(percent5 ~ Condition, data = age_vegi_cond_duration) # just Condition IV

percents6_m1_dur_av <- lm(percent6 ~ Condition, data = age_vegi_cond_duration) # just Condition IV

stargazer(percents1_m1_dur_av, percents2_m1_dur_av, percents3_m1_dur_av,  percents4_m1_dur_av, percents5_m1_dur_av, percents6_m1_dur_av, align = T, dep.var.labels = c("Domestic Charge", "International Charge", "Domestic Apprehension", "International Apprehension", "Domestic Conviction", "International Conviction"), type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.35: Effect of Mentalization on Charge, Apprehension and Conviction Estimates, Time-Limited", model.names = T, single.row = T) # no significant effects

### Duration CACE 

age_vegi_cond_duration <- age_vegi_cond_duration %>%
  mutate(followup_ittd = ifelse(Condition == 1 & followup3_1 == 1, 1, 0))

cace_iv_percent1_dur_av <- ivreg(percent1 ~ followup_ittd, ~Condition, data = age_vegi_cond_duration)

cace_iv_percent2_dur_av <- ivreg(percent2 ~ followup_ittd, ~Condition, data = age_vegi_cond_duration)

cace_iv_percent3_dur_av <- ivreg(percent3 ~ followup_ittd, ~Condition, data = age_vegi_cond_duration)

cace_iv_percent4_dur_av <- ivreg(percent4 ~ followup_ittd, ~Condition, data = age_vegi_cond_duration)

cace_iv_percent5_dur_av <- ivreg(percent5 ~ followup_ittd, ~Condition, data = age_vegi_cond_duration)

cace_iv_percent6_dur_av <- ivreg(percent6 ~ followup_ittd, ~Condition, data = age_vegi_cond_duration)

stargazer(cace_iv_percent1_dur_av, cace_iv_percent2_dur_av, cace_iv_percent3_dur_av, cace_iv_percent4_dur_av, cace_iv_percent5_dur_av, cace_iv_percent6_dur_av, type = 'html', title = "Table OA.36: CACE for Mentalization on Charge, Apprehension and Conviction Estimates, Time-Limited") 


## Robustness Check for Non-naivete

percent3_followup_av <- lm(percent3 ~ Condition + age + Nationality + NatID + Gender + Religion + Race + PolID + Combatant + CombExp + ConflZone + IHLScore + followup2_1, data = age_vegi_cond) # Condition and covariates, plus non-naivete question

stargazer(percent3_followup_av, type = 'html', title = "Table OA.37: Robustness Check for Non-naivete on Domestic Apprehension") 

## Mediation Effects

### Single Mediation of Condition effect on percent3 by Emotions Score
med.fit.percent3.av <- lm(EmotionScore ~ Condition, data = age_vegi_cond)
out.fit.percent3.av <- lm(percent3 ~ EmotionScore + Condition, data = age_vegi_cond)
med.out.percent3.av <- mediate(med.fit.percent3.av, out.fit.percent3.av, treat = "Condition", mediator = "EmotionScore", robustSE = T, sims = 1000)
summary(med.out.percent3.av) # no significant effects
plot(med.out.percent3.av, main = "Figure OA.18: ACME of EmotionScore on Percent3")

### Single Mediation of Condition effect on percent3 by Morals Score
med.fit2.percent3.av <- lm(MoralScore ~ Condition, data = age_vegi_cond)
out.fit2.percent3.av <- lm(percent3 ~ MoralScore + Condition, data = age_vegi_cond)
med.out2.percent3.av <- mediate(med.fit2.percent3.av, out.fit2.percent3.av, treat = "Condition", mediator = "MoralScore", robustSE = T, sims = 1000)
summary(med.out2.percent3.av) # no significant effects
plot(med.out2.percent3.av, main = "Figure OA.19: ACME of MoralScore on Percent3")


```

## Exploratory Analysis of Mediation of Association of MoralScore (X) and Sanction Perceptions (Y) by IHLScore (M)

```{r, results = "asis"}

# Mediation of Association of MoralScore (X) and Sanction Perceptions (Y) by IHLScore (M)

## ACME Method
med.fit.percent <- lm(IHLScore ~ MoralScore, data = emotions_survey_text)
out.fit.percent <- lm(percent3 ~ IHLScore + MoralScore, data = emotions_survey_text)
med.out.percent <- mediate(med.fit.percent, out.fit.percent, treat = "MoralScore", mediator = "IHLScore", robustSE = T, sims = 1000)
summary(med.out.percent) # mediation effects (ACME) are significant 
plot(med.out.percent, main = "Figure OA.20: ACME of IHLScore on Association of MoralScore and Percent3") # plot the mediation effects
med.boot.percent <- mediate(med.fit.percent, out.fit.percent, boot = T, treat = "MoralScore", mediator = "IHLScore", sims = 1000) # bootstrap
summary(med.boot.percent) # significant mediation effects (ACME) with bootstrap
plot(med.boot.percent, main = "Figure OA.21: ACME of IHLScore on Association of MoralScore and Percent3, Bootstrap") # plot the mediation efects

## Baron and Kenny (1986) Mediation Procedure
fit.percent <- lm(percent3 ~ MoralScore, data = emotions_survey_text)
summary(fit.percent) # significant total effect
fita.percent <- lm(IHLScore ~ MoralScore, data = emotions_survey_text)
summary(fita.percent) # path A is significant
fitb.percent <- lm(percent3 ~ IHLScore + MoralScore, data = emotions_survey_text)
summary(fitb.percent) # Significant mediation effects
fitc.percent <- lm(MoralScore ~ percent3 + IHLScore, data = emotions_survey_text)
summary(fitc.percent) # violates assumption of Baron Kenny procedure
stargazer(fit.percent, fita.percent,  fitb.percent, fitc.percent, align = T, type = 'html', intercept.bottom = F, intercept.top = T, ci = F, digits = 2, title = "Table OA.38: Mediation  Effect of IHLScore on Association of MoralScore and Percent3, Baron and Kenny Procedure", model.names = T, single.row = T)

sobel(emotions_survey_text$MoralScore, emotions_survey_text$IHLScore, emotions_survey_text$percent3) # sobel significance test of mediation effect

mediation.test(emotions_survey_text$IHLScore, emotions_survey_text$MoralScore, emotions_survey_text$percent3) # effect of MoralScore on Percent3 is significantly mediated by IHLScore

```


## Bar Graph of Percentages

```{r, results = "asis"}
percents_data <- data.frame(RiskType = c("Domestic Charge", "International Charge", "Domestic Apprehension", "International Apprehension", "Domestic Conviction",  "International Conviction"), Percent = c(round(mean(emotions_survey_text$percent1)), round(mean(emotions_survey_text$percent2)), round(mean(emotions_survey_text$percent3)), round(mean(emotions_survey_text$percent4)), round(mean(emotions_survey_text$percent5)), round(mean(emotions_survey_text$percent6)))) 
percents_data 

# Basic barplot

percents_barplot <- 
    ggplot(data = percents_data, aes(x = RiskType, y = Percent, fill = RiskType)) + 
  geom_bar(stat = "identity", width = 0.5, color = "black", position = position_dodge()) + geom_text(aes(label = Percent), vjust = 1.6, color = "white", size = 3.5) + theme_minimal() +
  theme(axis.text.x = element_blank()) + 
  ggtitle("Mean Sanction Risk Perceptions (All Subjects)")
percents_barplot

```

## Combatant Knowledge of IHL, By Type of Combatant and Experience
```{r, results = "asis"}

combatant_data  <- data.frame(CombatType = c("Government Combatant", "Other Combatant", "Civilian", "In Combat", "Near Combat", "Neither In/Near Combat"), IHLScore = c(round(mean(emotions_survey_text$IHLScore[emotions_survey_text$combat1 == "Yes, government soldier"]), digits = 2), round(mean(emotions_survey_text$IHLScore[emotions_survey_text$combat1 == "Yes, other combatant"]), digits = 2), round(mean(emotions_survey_text$IHLScore[emotions_survey_text$combat1 == "No"]), digits = 2), round(mean(emotions_survey_text$IHLScore[emotions_survey_text$combat2 == "Yes, in combat"]), digits = 2), round(mean(emotions_survey_text$IHLScore[emotions_survey_text$combat2 == "Yes, near combat"]), digits = 2), round(mean(emotions_survey_text$IHLScore[emotions_survey_text$combat2 == "No"]), digits = 2)))
combatant_data 

# Basic barplot

combat_barplot <- 
    ggplot(data = combatant_data, aes(x = CombatType, y = IHLScore, fill = CombatType)) + 
  geom_bar(stat = "identity", width = 0.5, color = "black", position = position_dodge()) + theme_minimal() + 
  geom_text(aes(label = IHLScore), vjust = 1.6, color = "white", size = 3.5) + 
  theme(axis.text.x = element_blank()) + 
  ggtitle("Knowledge of IHL by Combat Status")
combat_barplot

```

## Mediation of Association of CombExp (X), ConflZone (X), PolID (X), and NatID (X) with MoralScore (Y) by IHLScore (M)

```{r, results = "asis"}
# Mediation of Combat Experience (X) on MoralScore (Y) by IHLScore (M)

## ACME Method
med.fit.combexp <- lm(IHLScore ~ CombExp, data = emotions_survey_text) # CombExp (X) on IHLScore (M)
out.fit.combexp <- lm(MoralScore ~ IHLScore + CombExp, data = emotions_survey_text) # CombatExp (X) and IHLScore (M) on MoralScore (Y), 
med.out.combexp <- mediate(med.fit.combexp, out.fit.combexp, treat = "CombExp", mediator = "IHLScore", sims = 1000)
summary(med.out.combexp) # significant mediation effects (ACME)
plot(med.out.combexp, main = "Figure OA.22: ACME of IHLScore on Association of CombExp and MoralScore") # plot the mediation effects
med.boot.combexp <- mediate(med.fit.combexp, out.fit.combexp, boot = T, treat = "CombExp", mediator = "IHLScore", sims = 1000) # bootstrap
summary(med.boot.combexp) # significant mediation effects (ACME) with bootstrap
plot(med.boot.combexp, main = "Figure OA.23: ACME of IHLScore on Association of CombExp and MoralScore, Bootstrap") # plot the mediation efects

## Baron and Kenny (1986) Mediation Procedure
fit.combexp <- lm(MoralScore ~ CombExp, data = emotions_survey_text)
summary(fit.combexp) # total effect, path c
fita.combexp <- lm(IHLScore ~ CombExp, data = emotions_survey_text)
summary(fita.combexp) # path A (X on M)
fitb.combexp <- lm(MoralScore ~ IHLScore + CombExp, data = emotions_survey_text)
summary(fitb.combexp) # path B (M on Y, controlling for X), IHL Score significantly mediates effect of CombExp on MoralScore
fitc.combexp <- lm(CombExp ~ MoralScore + IHLScore, data = emotions_survey_text)
summary(fitc.combexp) # reverse path c (Y on X, controlling for M), violating Baron and Kenny assumptions because significant
stargazer(fit.combexp, fita.combexp, fitb.combexp, fitc.combexp, type = 'html', title = "Table OA.39: Mediation of Association of Combat Experience (X) and MoralScore (Y) by IHLScore (M), Baron and Kenny Method")

sobel(emotions_survey_text$CombExp, emotions_survey_text$IHLScore, emotions_survey_text$MoralScore) # sobel significance test of mediation effect

mediation.test(emotions_survey_text$IHLScore, emotions_survey_text$CombExp, emotions_survey_text$MoralScore) # Association of CombExp and MoralScore is significantly mediated by IHLScore

# Mediation of Conflict Zone (X) on MoralScore (Y) by IHLScore (M)

## ACME Method
med.fit.conflzone <- lm(IHLScore ~  ConflZone, data = emotions_survey_text)
out.fit.conflzone <- lm(MoralScore ~ IHLScore + ConflZone, data = emotions_survey_text)
med.out.conflzone <- mediate(med.fit.conflzone, out.fit.conflzone, treat = "ConflZone", mediator = "IHLScore", robustSE = T, sims = 1000)
summary(med.out.conflzone) # significant mediation effects
plot(med.out.conflzone, main = "Figure OA.24: ACME of IHLScore on Association of ConflZone and MoralScore") # plot the mediation effects (ACME)
med.boot.conflzone <- mediate(med.fit.conflzone, out.fit.conflzone, boot = T, treat = "ConflZone", mediator = "IHLScore", sims = 1000) # bootstrap
summary(med.boot.conflzone) # significant mediation effects (ACME) with bootstrap
plot(med.boot.conflzone, main = "Figure OA.25: ACME of IHLScore on Association of ConflZone and MoralScore, Bootstrap") # plot the mediation efects

## Baron and Kenny (1986) Mediation Procedure
fit.conflzone <- lm(MoralScore ~ ConflZone, data = emotions_survey_text)
summary(fit.conflzone) # total effect significant
fita.conflzone <- lm(IHLScore ~ ConflZone, data = emotions_survey_text)
summary(fita.conflzone) # path A significant
fitb.conflzone <- lm(MoralScore ~ IHLScore + ConflZone, data = emotions_survey_text)
summary(fitb.conflzone) # path B significant, significant mediation effect
fitc.conflzone <- lm(ConflZone ~ MoralScore + IHLScore, data = emotions_survey_text)
summary(fitc.conflzone) 
stargazer(fit.conflzone, fita.conflzone, fitb.conflzone, fitc.conflzone, type = 'html', title = "Table OA.40: Mediation of Association of ConflZone (X) with MoralScore (Y) by IHLScore (M), Baron and Kenny Method")
sobel(emotions_survey_text$ConflZone, emotions_survey_text$IHLScore, emotions_survey_text$MoralScore) # sobel significance test of mediation effect
mediation.test(emotions_survey_text$IHLScore, emotions_survey_text$ConflZone, emotions_survey_text$MoralScore) # significant mediation effects

# Mediation of NatID (X) on MoralScore (Y) by IHLScore (M)

## ACME Method
med.fit.natid <- lm(IHLScore ~  NatID, data = emotions_survey_text)
out.fit.natid <- lm(MoralScore ~ IHLScore + NatID, data = emotions_survey_text)
med.out.natid <- mediate(med.fit.natid, out.fit.natid, treat = "NatID", mediator = "IHLScore", robustSE = T, sims = 1000)
summary(med.out.natid) # significant mediation effects (ACME)
plot(med.out.natid, main = "Figure OA.26: ACME of IHLScore on Association of NatID and MoralScore") # plot the mediation effects
med.boot.natid <- mediate(med.fit.natid, out.fit.natid, boot = T, treat = "NatID", mediator = "IHLScore", sims = 1000) # bootstrap
summary(med.boot.natid) # significant mediation effects (ACME) with bootstrap
plot(med.boot.natid, main = "Figure OA.27: ACME of IHLScore on Association of NatID and MoralScore, Bootstrap") # plot the mediation efects

## Baron and Kenny (1986) Mediation Procedure
fit.natid <- lm(MoralScore ~ NatID, data = emotions_survey_text)
summary(fit.natid) # significant total effect
fita.natid <- lm(IHLScore ~ NatID, data = emotions_survey_text)
summary(fita.natid) # path A significant
fitb.natid <- lm(MoralScore ~ IHLScore + NatID, data = emotions_survey_text)
summary(fitb.natid) # path B signficant, significant mediation
fitc.natid <- lm(NatID ~ MoralScore + IHLScore, data = emotions_survey_text)
summary(fitc.natid) 
stargazer(fit.natid, fita.natid, fitb.natid, fitc.natid, type = 'html', title = "Table OA.41: Mediation Association of NatID (X) with MoralScore (Y) by IHLScore (M), Baron and Kenny Method")
sobel(emotions_survey_text$NatID, emotions_survey_text$IHLScore, emotions_survey_text$MoralScore) # sobel significance test of mediation effect
mediation.test(emotions_survey_text$IHLScore, emotions_survey_text$NatID, emotions_survey_text$MoralScore) # significant mediation effects 

# Mediation of PolID (X) on MoralScore (Y) by IHLScore (M)

## ACME Method
med.fit.polid <- lm(IHLScore ~ PolID, data = emotions_survey_text)
out.fit.polid <- lm(MoralScore ~ IHLScore + PolID, data = emotions_survey_text)
med.out.polid <- mediate(med.fit.polid, out.fit.polid, treat = "PolID", mediator = "IHLScore", robustSE = T, sims = 1000)
summary(med.out.polid) # NO significant mediation effects (ACME)
plot(med.out.polid, main = "Figure OA.28: ACME of IHLScore on Association of PolID and MoralScore") # plot the mediation effects
med.boot.polid <- mediate(med.fit.polid, out.fit.polid, boot = T, treat = "PolID", mediator = "IHLScore", sims = 1000) # bootstrap
summary(med.boot.polid) # NO significant mediation effects (ACME) with bootstrap
plot(med.boot.polid, main = "Figure OA.29: ACME of IHLScore on Association of PolID and MoralScore, Bootstrap") # plot the mediation efects

## Baron and Kenny (1986) Mediation Procedure
fit.polid <- lm(MoralScore ~ PolID, data = emotions_survey_text)
summary(fit.polid) # significant total effect
fita.polid <- lm(IHLScore ~ PolID, data = emotions_survey_text)
summary(fita.polid) # no significant path a effect
fitb.polid <- lm(MoralScore ~ IHLScore + PolID, data = emotions_survey_text)
summary(fitb.polid)
fitc.polid <- lm(PolID ~ MoralScore + IHLScore, data = emotions_survey_text)
summary(fitc.polid) 
stargazer(fit.polid, fita.polid, fitb.polid, fitc.polid, type = 'html', title = "Table OA.42: Mediation of Association of PolID (X) with MoralScore (Y) by IHLScore (M), Baron and Kenny Method")
sobel(emotions_survey_text$PolID, emotions_survey_text$IHLScore, emotions_survey_text$MoralScore) # sobel significance test of mediation effect
mediation.test(emotions_survey_text$IHLScore, emotions_survey_text$PolID, emotions_survey_text$MoralScore) # NO significant mediation effect

```



